home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / IPDUMP.C < prev    next >
Text File  |  1990-07-10  |  2KB  |  91 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "timer.h"
  6. #include "iface.h"
  7. #include "ip.h"
  8. #include "trace.h"
  9. #include "netuser.h"
  10.  
  11. extern FILE *trfp;
  12.  
  13. int
  14. ip_dump(bpp,check)
  15. struct mbuf **bpp;
  16. int check;
  17. {
  18.     void tcp_dump(),udp_dump(),icmp_dump();
  19.     struct ip ip;
  20.     int16 ip_len;
  21.     int16 offset;
  22.     int16 csum;
  23.  
  24.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  25.         return;
  26.  
  27.     fprintf(trfp,"IP:");
  28.     /* Sneak peek at IP header and find length */
  29.     ip_len = ((*bpp)->data[0] & 0xf) << 2;
  30.     if(ip_len < IPLEN){
  31.         fprintf(trfp," bad header\n");
  32.         return;
  33.     }
  34.     if(check)
  35.         csum = cksum(NULLHEADER,*bpp,ip_len);
  36.     else
  37.         csum = 0;
  38.  
  39.     ntohip(&ip,bpp);    /* Can't fail, we've already checked ihl */
  40.  
  41.     /* Trim data segment if necessary. */
  42.     trim_mbuf(bpp,ip.length - ip_len);    /* Length of data portion */
  43.     fprintf(trfp," len %u",ip.length);
  44.     fprintf(trfp," %s",inet_ntoa(ip.source));
  45.     fprintf(trfp,"->%s ihl %u ttl %u",
  46.         inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
  47.     if(ip.tos != 0)
  48.         fprintf(trfp," tos %s",put_tos(ip.tos));
  49.     offset = (ip.fl_offs & F_OFFSET) << 3;
  50.     if(offset != 0 || (ip.fl_offs & MF))
  51.         fprintf(trfp," id %u offs %u",ip.id,offset);
  52.     if(ip.fl_offs & DF)
  53.         fprintf(trfp," DF");
  54.     if(ip.fl_offs & MF){
  55.         fprintf(trfp," MF");
  56.         check = 0;    /* Bypass host-level checksum verify */
  57.     }
  58.     if(ip.optlen != 0){
  59.         int i;
  60.         char *p = ip.options;
  61.  
  62.         fprintf(trfp," opt ");
  63.         for(i = 0; i < ip.optlen; i++)
  64.             fprintf(trfp,"%02x",uchar(*p++));
  65.     }
  66.     if(csum != 0)
  67.         fprintf(trfp," CHECKSUM ERROR (%u)",csum);
  68.  
  69.     if(offset != 0){
  70.         fprintf(trfp,"\n");
  71.         return;
  72.     }
  73.     switch(uchar(ip.protocol)){
  74.     case TCP_PTCL:
  75.         fprintf(trfp," prot TCP\n");
  76.         tcp_dump(bpp,ip.source,ip.dest,check);
  77.         break;
  78.     case UDP_PTCL:
  79.         fprintf(trfp," prot UDP\n");
  80.         udp_dump(bpp,ip.source,ip.dest,check);
  81.         break;
  82.     case ICMP_PTCL:
  83.         fprintf(trfp," prot ICMP\n");
  84.         icmp_dump(bpp,ip.source,ip.dest,check);
  85.         break;
  86.     default:
  87.         fprintf(trfp," prot %u\n",uchar(ip.protocol));
  88.         break;
  89.     }
  90. }
  91. ə